//
// Created by lenovo on 2023/11/30.
//

#ifndef QJSONMESH_H
#define QJSONMESH_H
#pragma once
#include <qlinemesh.h>
#include <Qt3DRender/qgeometryrenderer.h>
#include <qvector3d.h>
#include <Qt3dRender/qattribute.h>
#include <Qt3dRender/qgeometry.h>
#include <Qt3dRender/qbuffer.h>
#include <Qt3DCore/qentity.h>
#include <Qt3DExtras/QPhongMaterial>
using ATTRIBUTE_TYPE = Qt3DRender::QAttribute;
using GEOMETRY_TYPE  = Qt3DRender::QGeometry;
using BUFFER_TYPE    = Qt3DRender::QBuffer;
class QJsonMesh : public Qt3DRender::QGeometryRenderer
{
    Q_OBJECT
public:
    ATTRIBUTE_TYPE* m_positionAttribute = nullptr;
    ATTRIBUTE_TYPE* m_indexAttribute    = nullptr;
    BUFFER_TYPE*    m_vertexBuffer      = nullptr;
    BUFFER_TYPE*    m_indexBuffer       = nullptr;
    GEOMETRY_TYPE*  geometry            = nullptr;
public:
    explicit QJsonMesh(std::string jsonfile, Qt3DCore::QNode* root = Q_NULLPTR);
    ~QJsonMesh() override;
private:
    void loadJsonMesh(const std::string& jsonfile);
    QVector<QVector3D> vertices;
    QVector<unsigned int> indices;
    QVector<unsigned int> lineindices;
    Qt3DExtras::QPhongMaterial* lineMaterial;
    Qt3DCore::QEntity* lineEntity;
    QLineMesh* line_mesh;
};
#endif //QJSONMESH_H
